package bulidStream;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @Author wangtengyu
 * @Create 2018-06-06-16:18
 */
public class FileDemo {
    public static void main(String[] args) {
        long uniquewords=0;
        try {
            Stream<String> stream= Files.lines(Paths.get("src/main/resources/data.txt"), Charset.defaultCharset());
            uniquewords=stream.flatMap(lines-> Arrays.stream(lines.split(" "))).distinct().count();
            System.out.println(uniquewords);
            //stream.forEach(System.out::println);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
